﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.BLL
{
    public class StockOutHeader
    {
        #region 封装属性

        private string mStockOutNum;

        public string StockOutNum
        {
            get { return mStockOutNum; }
            set { mStockOutNum = value; }
        }

        private StockOutType mStockOutTypeName;

        public StockOutType StockOutTypeName
        {
            get { return mStockOutTypeName; }
            set { mStockOutTypeName = value; }
        }

        private Department mDepartmentName;

        public Department DepartmentName
        {
            get { return mDepartmentName; }
            set { mDepartmentName = value; }
        }

        private DateTime mStockOutDatetime;

        public DateTime StockOutDatetime
        {
            get { return mStockOutDatetime; }
            set { mStockOutDatetime = value; }
        }

        private string mCreatedBy;

        public string CreatedBy
        {
            get { return mCreatedBy; }
            set { mCreatedBy = value; }
        }

        private string mApprovalBy;

        public string ApprovalBy
        {
            get { return mApprovalBy; }
            set { mApprovalBy = value; }
        }

        private string mRemark;

        public string Remark
        {
            get { return mRemark; }
            set { mRemark = value; }
        }

        private string mStatus;

        public string Status
        {
            get { return mStatus; }
            set { mStatus = value; }
        }

        #endregion

        private IStockOutHeaderDAL dal;

        public StockOutHeader()
        {
            dal = Adapter.GetStockOutHeader();
        }

        public void FetchObject(IDataReader dr)
        {
            if (dr != null)
            {
                mApprovalBy = ConvertDataType.CheckFiledString(dr["approval_by"]);
                mCreatedBy  = ConvertDataType.CheckFiledString(dr["created_by"]);
                mDepartmentName.DepartmentName = ConvertDataType.CheckFiledString(dr["department_name"]);
                mRemark = ConvertDataType.CheckFiledString(dr["remark"]);
                mStatus = ConvertDataType.CheckFiledString(dr["status"]);
                mStockOutDatetime = ConvertDataType.CheckFiledDateTime(dr["stock_out_time"]);
                mStockOutNum = ConvertDataType.CheckFiledString(dr["stock_out_num"]);
                mStockOutTypeName.StockOutTypeName = ConvertDataType.CheckFiledString(dr["stock_out_type_name"]);
            }
        }

        public DataTable DisplayByStatus(string status)
        {
            return dal.SelectByStatus(status);
        }

        public DataTable Filter(string StockOutNum, string StockOutTypeName, string DepartmentName, string Status)
        {
            return dal.Select(StockOutNum, StockOutTypeName, DepartmentName, Status);
        }

        public bool CreateStockOutHeader(StockOutHeader header)
        {
            return dal.Insert(header.StockOutNum, header.StockOutTypeName.StockOutTypeName, header.StockOutDatetime, header.DepartmentName.DepartmentName, header.CreatedBy, header.ApprovalBy, header.Remark, header.Status) > 0 ? true : false;
        }

        public bool RemoveStockOutHeader(StockOutHeader header)
        {
            return dal.Delete(header.StockOutNum) > 0 ? true : false;   
        }

        public bool SetStockOutHeader(StockOutHeader header)
        {
            return dal.Update(header.StockOutNum, header.StockOutTypeName.StockOutTypeName, header.StockOutDatetime, header.DepartmentName.DepartmentName, header.CreatedBy, header.ApprovalBy, header.Remark, header.Status) > 0 ? true : false;
        }
    } 
}
